# -*- coding: utf-8 -*-

import datetime
from celery.schedules import crontab
from django.conf import settings

from news.models import NewsEdition

# Celery database backend
CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['json']

CELERY_TIMEZONE = settings.TIME_ZONE

# 最大并发任务数
CELERYD_OPTS="--concurrency=4"

# 每日后台任务
## 注意！ args只接受tuple，传单个参数时一定要保留逗号 ##

CELERYBEAT_SCHEDULE = {
    
    #### basic_info ####
    
    # 同步个股券商基本信息 8:15 A.M
    'Import stocks info': {
        'task': 'basic_info.tasks.import_stocks_info',
        'schedule': crontab(hour=8, minute=15, day_of_week='1-5'),
    },

    #### institutes ####
    
    # 同步投顾基本信息 9:00 A.M
    'Generate daily tougu report': {
        'task': 'institutes.tasks.generate_daily_tougu_report',
        'schedule': crontab(hour=9, minute=0, day_of_week='1-5'),
        'args': (NewsEdition.MORNING, ),
    },
    # 同步每日券商会议 1:00 P.M 1小时一次
    'Import daily meeting': {
        'task': 'institutes.tasks.import_daily_meeting',
        'schedule': crontab(hour='13-18', minute=0, day_of_week='1-5'),
    },

    #### news ####
    
    # 同步每日头条、头条摘要、新闻聚类、聚类摘要 9:00 A.M 1小时一次
    'Import daily headlines, summary, cluster':{
        'task':'news.tasks.import_daily_headlines_summary_cluster',
        'schedule': crontab(hour='9-18', minute='*/5', day_of_week='1-5'),
        'args': (NewsEdition.MORNING, )
    },
    # 同步每日个股、行业新闻、行业研报、公司公告 9:00 A.M 1小时一次
    'Import daily stock news and more':{
        'task':'news.tasks.import_stock_news_and_more',
        'schedule': crontab(hour='10-17', minute='*/30', day_of_week='1-5'),
    },
    
    #### companies ####
     
    # 统计每日高管互动 8:00 P.M
    'Import daily QA': {
        'task': 'companies.tasks.import_daily_qa',
        'schedule': crontab(hour='20', minute=0, day_of_week='1-5'),
    },
    # 统计每日资金流数据 9 P.M 10分钟一次
    'Sync money flow data': {
        'task': 'companies.tasks.sync_moneyflow',
        'schedule': crontab(hour='9-17', minute='*/10', day_of_week='1-5'),
    },
    # 同步每日传闻求证
    'Sync chuanwen data': {
        'task': 'companies.tasks.process_daily_chuanwen',
        'schedule': crontab(hour='12,19,22', minute='0', day_of_week='1-5'),
    },

}
